﻿using Microsoft.JSInterop;

namespace MyDocuments.Client
{
    public static class JSLibrary
    {
        public static event EventHandler? Ctrl_S_Event; // Ctrl + s 保存
        public static event EventHandler? Ctrl_F2_Event;   // F2 重命名
        public static event EventHandler? Ctrl_N_Event;  // Ctrl + n 新建
        public static event EventHandler? Ctrl_Del_Event;  // Ctrl + Del 删除
        public static event EventHandler? Ctrl_F5_Event;  // Ctrl + Del 删除
        public static event EventHandler? Ctrl_P_Event;  // Ctrl + p 预览
        public static event EventHandler? Ctrl_F_Event;  // Ctrl + f 搜索
        public static event EventHandler? Ctrl_Q_Event;  // Ctrl + q 分享

        public static bool IsSaveEventNull(string eventName)
        {
            switch (eventName)
            {
                case nameof(Ctrl_F5_Event):
                    return Ctrl_F5_Event == null;

                case nameof(Ctrl_S_Event):
                    return Ctrl_S_Event == null;

                case nameof(Ctrl_F2_Event):
                    return Ctrl_F2_Event == null;

                case nameof(Ctrl_N_Event):
                    return Ctrl_N_Event == null;

                case nameof(Ctrl_Del_Event):
                    return Ctrl_Del_Event == null;

                case nameof(Ctrl_P_Event):
                    return Ctrl_P_Event == null;

                case nameof(Ctrl_Q_Event):
                    return Ctrl_Q_Event == null;

                case nameof(Ctrl_F_Event):
                    return Ctrl_F_Event == null;

                default:
                    return false;
            }
        }

        [JSInvokable]
        public static void PriviewEvent()
        {
            if (Ctrl_P_Event != null) Ctrl_P_Event.Invoke(null, null);
        }

        [JSInvokable]
        public static void SaveEvent() {
            if (Ctrl_S_Event != null) Ctrl_S_Event.Invoke(null, null);
        }

        [JSInvokable]
        public static void F2Event() {
            if (Ctrl_F2_Event != null) Ctrl_F2_Event.Invoke(null, null);
        }

        [JSInvokable]
        public static void NEvent()
        {
            if (Ctrl_N_Event != null) Ctrl_N_Event.Invoke(null, null);
        }

        [JSInvokable]
        public static void DelEvent()
        {
            if (Ctrl_Del_Event != null) Ctrl_Del_Event.Invoke(null, null);
        }

        [JSInvokable]
        public static void F5Event()
        {
            if (Ctrl_F5_Event != null) Ctrl_F5_Event.Invoke(null, null);
        }

        [JSInvokable]
        public static void ShareEvent()
        {
            if (Ctrl_Q_Event != null) Ctrl_Q_Event.Invoke(null, null);
        }

        [JSInvokable]
        public static void SearchEvent()
        {
            if (Ctrl_F_Event != null) Ctrl_F_Event.Invoke(null, null);
        }
    };
}
